// 运行时配置

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://next.umijs.org/docs/api/runtime-config#getinitialstate
import RightContent from '@/components/RightContent';
import { requestConfig } from '@/utils/request';
import { history } from '@umijs/max';

import 'dayjs/locale/zh-cn';

// export async function getInitialState() {
//   console.log('---')
//   return { name: '@umijs/max1' };
// }

export async function getInitialState() {
  const fetchUserInfo = async () => {
    try {
      const user = localStorage.getItem('user');
      if (user) {
        return JSON.parse(user);
      } else {
        history.push('/login');
      }

      return undefined;
    } catch (error) {
      // history.push('/Login');
      console.log(error, 'error');
    }
    return undefined;
  };
  // 如果不是登录页面，执行
  console.log(history.location.pathname, '==');
  if (history.location.pathname !== '/login') {
    const currentUser = await fetchUserInfo();
    return {
      fetchUserInfo,
      currentUser,
    };
  }
  return {
    fetchUserInfo,
    // settings: defaultSettings,
  };
}

export const layout = () => {
  return {
    logo: null,
    title: 'sms服务',
    menu: {
      locale: false,
    },
    token: {
      // colorBgAppListIconHover: 'rgba(0,0,0,0.06)',
      // colorTextAppListIconHover: 'rgba(255,255,255,0.95)',
      // colorTextAppListIcon: 'rgba(255,255,255,0.85)',
      header: {
        heightLayoutHeader: 64,
      },
      sider: {
        colorBgCollapsedButton: '#fff',
        colorTextCollapsedButtonHover: 'rgba(0,0,0,0.65)',
        colorTextCollapsedButton: 'rgba(0,0,0,0.45)',

        colorBgMenuItemCollapsedHover: 'rgba(0,0,0,0.06)',
        colorBgMenuItemCollapsedSelected: 'rgba(0,0,0,0.15)',
        colorMenuItemDivider: 'rgba(255,255,255,0.15)',
        // colorBgMenuItemHover: 'rgba(0,0,0,0.06)',
        colorBgMenuItemSelected: 'rgba(0,0,0,0.15)',
        colorTextMenuSelected: '#fff',
        colorTextMenuItemHover: 'rgba(255,255,255,0.75)',
        colorTextMenu: 'rgba(255,255,255,0.75)',
        colorTextMenuSecondary: 'rgba(255,255,255,0.65)',
        colorTextMenuTitle: 'rgba(255,255,255,0.95)',
        colorTextMenuActive: 'rgba(255,255,255,0.95)',
        colorTextSubMenuSelected: '#fff',

        colorMenuBackground: '#001529',
        colorBgMenuItemHover: '#fff',
        colorBgMenuItemSelected: '#1890ff',
        colorTextMenuActive: '#fff',
        colorTextMenuSelected: '#fff',
        colorTextMenuTitle: '#fff',
        colorTextMenu: 'hsla(0,0%,100%,.65);',

        // colorMenuBackground: '#001529',
        // colorHeaderTitle:'blue'
        // colorTextMenu:
      },
    },
    rightContentRender: () => <RightContent />,
  };
};

export const request = requestConfig;
